package com.bqtt.tumor.demo.business;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.bqtt.tumor.demo.common.MyBeanFactory;
import com.bqtt.tumor.demo.data_access.ImageDAO;
import com.bqtt.tumor.demo.entity.Image;

public class ImageService {

	private static ImageDAO imageDAO = (ImageDAO) MyBeanFactory.getBean("imageDAO");
	private static Logger log = LoggerFactory.getLogger(ImageService.class);

	public static List<Image> getList()
	{
		return imageDAO.findAll();
	}
	

	public static List<Image> searchByType(int i)
	{
		
		List<Image> result = imageDAO.findByProperty("type", i);
		return result;
	}
	
	public static List<Image> searchByCaseAndType(int case_id,int i)
	{
		Map<String,Object> params = new HashMap<String,Object>();
		params.put("case_id", case_id);
		params.put("type", i);
		List<Image> result = imageDAO.findByProperties(params);
		
		
		return result;
	}
	
	public static boolean add(Image image)
	{
		try
		{
			imageDAO.save(image);
			return true;
		}
		catch(Exception e)
		{
			log.error(e.getMessage());
	     	return false;	
		}
		
	}
	
	public static  Image getById(Integer id)
	{
		return imageDAO.findById(id);
	}
	
	
	public static boolean delete(Image image)
	{
			return imageDAO.delete(image);
		
	}
}
